package com.glory.dgcpcpda.activity.cpc;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.dgcpcpda.R;
import com.glory.dgcpcpda.activity.check.CheckInspectionActivity;
import com.glory.dgcpcpda.activity.check.NewCheckTableActivity;
import com.glory.dgcpcpda.activity.check.SearchCheckActivity;
import com.glory.dgcpcpda.adapter.CheckQueryListAdapter;
import com.glory.dgcpcpda.adapter.CpcAlarmInfoAdapter;
import com.glory.dgcpcpda.base.BaseActivity;
import com.glory.dgcpcpda.callback.CustomDialogEntityCallBack;
import com.glory.dgcpcpda.entity.AlarmInfo;
import com.glory.dgcpcpda.entity.CheckSheetEntity;
import com.glory.dgcpcpda.entity.EqpInfoEntity;
import com.glory.dgcpcpda.entity.LotInfoEntity;
import com.glory.dgcpcpda.entity.SheetInfoEntity;
import com.glory.dgcpcpda.entity.response.BaseResponseBean;
import com.glory.dgcpcpda.utils.LotUtils;
import com.glory.dgcpcpda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_Utils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class CpcControlInfoActivity extends BaseActivity {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.etEqpWork)
    FreeUI_ClearEditText etEqpWork;
    @BindView(R.id.tvRepairID)
    TextView tvRepairID;
    @BindView(R.id.tvRepairType)
    TextView tvRepairType;
    @BindView(R.id.tvPositionAndJobNo)
    TextView tvPositionAndJobNo;
    @BindView(R.id.rvAlarmInfoList)
    RecyclerView rvAlarmInfoList;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    private CpcAlarmInfoAdapter mAdapter;
    private String mEqpType;
    private String mLocation;
    private String mSelectorStr = "ALL";

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_cpc_info;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        tvTitle.setText("异常信息查询");
        tvBaseSubmit.setText("查询");
        initRecyclerView(rvAlarmInfoList,this);
        mAdapter = new CpcAlarmInfoAdapter(null);
        mAdapter.isFirstOnly(true);
        mAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        rvAlarmInfoList.setAdapter(mAdapter);
        initEdit2(etEqpWork,s -> initData());
    }

    @Override
    protected void initData() {
        requestData();
    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
                requestData();
                break;
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        requestData();
    }

    private void requestData() {
        FreeUI_EntityCallBack<BaseResponseBean<AlarmInfo>> callBack = new FreeUI_DialogEntityCallBack<BaseResponseBean<AlarmInfo>>
                (new TypeToken<BaseResponseBean<AlarmInfo>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<AlarmInfo>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(),true,getSupportFragmentManager())){
                    List<AlarmInfo> alarmInfoList = response.body().getResponse().getBody().getALARMLIST();
                    if (alarmInfoList.size() <= 0){
                        showConfirmDialog("暂无数据");
                    }
                    System.out.println("#########:"+alarmInfoList);
                    mAdapter.setNewData(alarmInfoList);
                }
            }

            @Override
            public void onError(Response<BaseResponseBean<AlarmInfo>> response) {
                super.onError(response);
                showToast("ERROR",false);

            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("AlarmId",getText(etEqpWork));
        NetUtils.requestPostNet("","EAPALARMCODE",this,map,callBack);
    }

}
